<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/payment.css?v=5">
<script type="text/javascript">

    $(function() {

        //初始化页面配置

        var titleName = "付款给希卫康";
        if ("{$type}" == "wangjing"){
            titleName = "望京医院定制支具在线支付"
        }
        initPage(titleName);

        var app = new Vue({
            el: '#container',
            data: {
                info: [],
            },
            methods: {

                index: indexPage,
                cancel: function() {
                    window.location.href = "/wechat/home";
                },
                save: function() {
                    var paymentId = $("input[name=paymentId]").val();
                    var customerId = $("input[name=customerId]").val();
                    var name = $("input[name=name]").val();
                    var number = $("input[name=number]").val();
                    var salesId = $("select[name=salesId]").val();
                    var amount = $("input[name=amount]").val();
                    var paymentContent = $("input[name=paymentContent]").val();
                    var receiveContact = $("input[name=receiveContact]").val();
                    var needInvoice = $("select[name=needInvoice]").val();
                    var invoiceName = $("input[name=invoiceName]").val();
                    var invoiceNumber = $("input[name=invoiceNumber]").val();
//                    var paymentContent = $("textarea[name=paymentContent]").val();

                    if(isNullOrEmpty(amount)) {
                        alert("请填写付款金额");
                        return false;
                    }

                    if(!checkMoney(amount)) {
                        alert("付款金额格式不正确");
                        return false;
                    }

                    if(isNullOrEmpty(name)) {
                        alert("请填写患者姓名");
                        return false;
                    }
                    if ("{$type}" == "wangjing") {
                        if (needInvoice != -1) {
                            if (needInvoice == 1) {
                                if (isNullOrEmpty(invoiceName)) {
                                    alert("请填写发票抬头");
                                    return false;
                                }
                                if (isNullOrEmpty(invoiceNumber)) {
                                    alert("请填写纳税人识别号");
                                    return false;
                                }
                            }
//                        if(isNullOrEmpty(receiveName)) {
//                            alert("请填写收件人姓名");
//                            return false;
//                        }
//                        if(isNullOrEmpty(receiveAddress)) {
//                            alert("请填写收件人地址");
//                            return false;
//                        }
                            if (isNullOrEmpty(receiveContact)) {
                                alert("请填写联系电话，用于接收电子发票");
                                return false;
                            }
                            if (!checkPhone(receiveContact)) {
                                alert("手机号位数不对");
                                return false;
                            }
                        }
                    }
//                    if(!isNullOrEmpty(number)) {
//                        if(!checkPhone(number)) {
//                            alert("联系电话位数不对");
//                            return false;
//                        }
//                    }

                    if(confirm("请确认是否付款？\n金额【  "+ amount +"元  】")){
                        $.ajax({
                            url:"/wechat/Payment/createPayment",
                            type:"post",
                            data:{
                                paymentId: paymentId,
                                customerId: customerId,
                                name: name,
                                amount: amount,
//                                number: number,
//                                salesId: salesId,
                                receiveContact: receiveContact,
                                paymentContent: paymentContent,
                                needInvoice: needInvoice,
                                invoiceName: invoiceName,
                                invoiceNumber: invoiceNumber,
                                type: "{$type}",
                            },

                            dataType:"JSON",
                            beforeSend:function(){
                                $("#loadingToast").show();
                                $("#submitBtn").hide();
                            },
                            complete:function(){
                                $('#loadingToast').hide();
                            },
                            success:function(data){
                                if(data.code != 200) {
                                    alert(data.msg);
                                    return false;
                                }
                                window.location.href = "/wechat/userCenter/payInfo/id/_"+data.payment_id;
                            },
                        })
                    }else{
                        return;
                    }
                }

            }
        })

        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("select[name=needInvoice]").change(function() {
            if($(this).val() == 1) {
                $(".item.invoice").show();
            } else {
                $(".item.invoice").hide();
            }
            if($(this).val() == -1) {
                $(".item.invoiceDetail").hide();
            } else {
                $(".item.invoiceDetail").show();
            }
            if($(this).val() == 2) {
                $(".item.invoiceName").show();
                $("input[name=invoiceName]").val($("input[name=name]").val());
            }
        });

        function checkMoney(amount){
            var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if(!(reg.test(amount))){
                return false;
            }
            return true;
        }
    });


</script>
<!--div class="hint-info">
    您将付款给希卫康。
</div-->
<div class="edit-content">
    <input type="text" style="display: none;" name="paymentId" value="{$info.payment_id}">
    <input type="text" style="display: none;" name="customerId" value="{$customerId}">
    <div class="item-1">
        <input type="text" name="amount" pattern="[0-9]*" placeholder="请输入付款金额">
    </div>
    <br/>
    <div class="item">
        <span>姓名</span>
        <input type="text" name="name" placeholder="必填，付款人或患者姓名">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <!--div class="item">
        <span>联系电话</span>
        <input type="text" name="number" pattern="[0-9]*" placeholder="选填">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div-->
    <!--div class="item">
        <span>销售：</span>
        <input id="salesId" type="text" readonly placeholder="选填">
        <select name="salesId">
            <option value="{$sales.employee_id}">请选择</option>
            {:getEmployeeSelectOptionHtml(2,0)}
        </select>
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div-->
    <div class="product-need" style="margin-bottom: 0" v-if="'{$type}' == 'wangjing'">
        <div class="item">
            <span>是否开发票</span>
            <input type="text" value="不开发票" name="needInvoice" readonly placeholder="">
            <select name="needInvoice" class="invoice-choose">
                <option value="-1">不开发票</option>
                <option value="1">公司发票</option>
                <option value="2">个人发票</option>
            </select>
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item invoice invoiceName" style="display: none;">
            <span>发票抬头</span>
            <input name="invoiceName" type="text" placeholder="请填写发票抬头">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item invoice" style="display: none;">
            <span>纳税人识别号</span>
            <input name="invoiceNumber" type="text" placeholder="请填纳税人识别号">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item invoiceDetail" style="display: none;">
            <span>联系电话</span>
            <input type="text" name="receiveContact" placeholder="手机号用于接收电子发票">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
    </div>
    <div class="item">
        <span>备注</span>
        <input type="text" name="paymentContent" placeholder="选填">
        <img class="icon-right" src="/Template/images/icon-right.png" alt="">
    </div>
    <!--div class="area">
        <textarea class="t-area" name="paymentContent" placeholder="选填"></textarea>
    </div-->
</div>

<div class="operation-btn">
    <div class="cancel-btn" v-on:click="cancel">取消</div>
    <div id="submitBtn" class="save-btn" v-on:click="save">付款</div>
</div>
<include file="./Template/footer.html" />

